#include <stdio.h>
#include <ctype.h>

#define MINE '*'
#define SAFE '.'
#define MAX_ROWS 100
#define MAX_COLUMNS 100
#define MAX_NEIGHBORS 8

int
	vx[MAX_NEIGHBORS] = {-1, -1, -1,  0,  0,  1,  1,  1},
	vy[MAX_NEIGHBORS] = {-1,  0,  1, -1,  1, -1,  0,  1};


int main ()
{
	int rows, columns, field, board[MAX_ROWS][MAX_COLUMNS], r, c, i, x, y;
	int *b, *nb;

	field = 1;
	if (scanf ("%d %d", &rows, &columns) > 0 && rows)
	{
		printf("Field #%d:\n", field);

		for (r = 0; r < rows; ++r)
			for (c = 0; c < columns; ++c)
				board[r][c] = '0';

		for (r = 0; r < rows; ++r)
		{
			for (c = 0; c < columns; ++c)
			{
				b = &board[r][c];
				do {i = getchar();} while (isspace(i));
				if (i == MINE)
				{
					*b = MINE;
					for (i = 0; i < MAX_NEIGHBORS; ++i)
					{
						x = r + vx[i];
						y = c + vy[i];
						if (x < 0 || y < 0 || x >= rows || y >= columns)
							continue;
						nb = &board[x][y];
						*nb += (*nb != MINE);
					}
				}
			}
		}

		for (r = 0; r < rows; ++r)
		{
			for (c = 0; c < columns; ++c)
			{
				putchar(board[r][c]);
			}
			putchar('\n');
		}

		++field;
	}
	while (scanf ("%d %d", &rows, &columns) > 0 && rows)
	{
		printf("\nField #%d:\n", field);

		for (r = 0; r < rows; ++r)
			for (c = 0; c < columns; ++c)
				board[r][c] = '0';

		for (r = 0; r < rows; ++r)
		{
			for (c = 0; c < columns; ++c)
			{
				b = &board[r][c];
				do {i = getchar();} while (isspace(i));
				if (i == MINE)
				{
					*b = MINE;
					for (i = 0; i < MAX_NEIGHBORS; ++i)
					{
						x = r + vx[i];
						y = c + vy[i];
						if (x < 0 || y < 0 || x >= rows || y >= columns)
							continue;
						nb = &board[x][y];
						*nb += (*nb != MINE);
					}
				}
			}
		}

		for (r = 0; r < rows; ++r)
		{
			for (c = 0; c < columns; ++c)
			{
				putchar(board[r][c]);
			}
			putchar('\n');
		}

		++field;
	}
}